


* Test dataset; 
libname home 'D:\Dropbox\Work - RA\regression 12 lag ret - (3.22.2022) Table 2 and 3 - US'; 
data base_t2; set home.data_table2; run; 


* Fit cross-sectional regression each period, compute number of stocks, and regression R2; 
ods select none; 
proc sort data=base_t2; by date; run; 
proc glm data=base_t2; 
	by date; 
	model ret=ret_t1 ret_t2 ret_t3 ret_t4 ret_t5 ret_t6 ret_t7 ret_t8 ret_t9 ret_t10 ret_t11 ret_t12; 
	where prc_prmth>=1 & NYSE_decile_rank>1; * Exclude penny & small.;
	ods output parameterestimates=est;
	ods output nobs=nobs; 
	ods output fitstatistics=stats;
run; quit; 
ods select all; 

proc transpose data=est out=est1; 
	by date; id parameter; var estimate;
run; 
data est1; set est1; Sum_ret_t2_12=sum(of ret_t:)-ret_t1; run; 


data nobs; set nobs; where label='Number of Observations Used'; run; 
proc sql;
	create table out as
	select a.*, b.N, c.RSquare
	from est1 a 
		left join Nobs b on a.date=b.date
		left join stats c on a.date=c.date;
quit;
data out; set out; AdjRSquare=1-(1-RSquare)*(N-1)/(N-13); run; 


proc print data=out (drop = _name_); 
	title1 "All CRSP common stocks with past 12 monthly returns (1931~2020)";	
	title2 "Excluding penny and small stocks (NYSE decile)";	
run; 
